<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>OOJS</title>
    <script src="../js/js02_oojs_02.js"></script>
    <link rel="stylesheet" href="../css/common.css">
</head>
<body>
    <h1>OOJS-封装</h1>
    <p class="msg"></p>
    <script>
        document.addEventListener("DOMContentLoaded",function(){
            let msg = document.querySelector(".msg");
            let stu1 = new Student("张三",20);
            console.log(Object.keys(stu1));
            msg.innerHTML += stu1.sayHello();
            msg.innerHTML += "<br>";
            stu1.name="李四";
            stu1.age=21;
            msg.innerHTML += stu1.sayHello();
            msg.innerHTML += "<br>";
            stu1.setAge(22);
            msg.innerHTML += stu1.sayHello();
            msg.innerHTML += "<br>";

            let stu2 = new Student2("王五");
            msg.innerHTML += stu2.sayHello();
            console.log(stu2[symbolAge]);
            console.log(Object.keys(stu2));
            msg.innerHTML += "<br>";

            stu2.setAge(23);
            msg.innerHTML += stu2.sayHello();
            msg.innerHTML += "<br>";

            let stu3 = new Student2("赵六");
            try{
                stu3.setAge(-1);
            }catch(e){
                msg.innerHTML += `<span class="danger">${e}<span>`;                 
            }

            Student.prototype.test = function(){
                console.log("原型链会自动更新");
            }
            stu1.test();

        })
    </script>
</body>
</html>